/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.cnam.mobileshopping.ws;

import java.util.Date;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;
import org.cnam.mobileShopping.entity.Category;
import org.cnam.mobileShopping.entity.Product;
import org.cnam.mobileshopping.ejb.product.ProductLocal;

/**
 * REST Web Service
 *
 * @author Administrateur
 */
@Stateless
@Path("product")
public class ProductResource {

    /** Creates a new instance of ProductResource */
    public ProductResource() {
    }

   @EJB(name="ejb/mobileshopping/product")
   ProductLocal productLocal;
   
   
    @GET
    @Path("getProductsByCategory")
    @Produces("application/json")
    public List<Product> getProductsByCategory(@QueryParam("category") Integer categoryId)
    {
        return productLocal.getProductsByCategory(categoryId);
    }
        
    @GET
    @Path("getCategoriesList")
    @Produces("application/json")
    public List<Category> getCategoriesList()
    {
        return productLocal.getCategories();
    }
    
    @GET
    @Path("getProductsForSynchro")
    @Produces("application/json")
    public List<Product> getProductsForSynchro(@QueryParam("lastupdatedatetime") Date lastupdate)
    {
//        List<Product> products = productLocal.getProductsForSynchro(lastupdate);
//        if(products != null) {
//            return Response.ok(products).build();
//        } else {
//            return Response.ok().build();
//        }
        return productLocal.getProductsForSynchro(lastupdate);
    }
    
    @GET
    @Path("addProductInReferenciel")
    @Produces("application/json")
    public Product addProductInReferenciel(@QueryParam("description") String description, @QueryParam("barcode") String barcode, @QueryParam("categoryid")  Integer categoryid)
    {
        return productLocal.addProduct(description, categoryid, barcode);
    }
    
}
